﻿
#######################################################################
# EFFECT LIST
#######################################################################
# !!! Remember to add all new effects with a short description here !!!
#######################################################################

blackmail_interaction_effect = {
	scope:actor = {
		if = {
			limit = { exists = scope:target }
			blackmail_target_with_secret_effect = { SECRET = scope:target TARGET = scope:recipient }
			reverse_add_opinion = {
				modifier = blackmailing_me_opinion
				target = scope:recipient
			}
		}
		if = {
			limit = { has_government = administrative_government }
			if = {
				limit = {
					scope:target = { is_criminal_for = scope:recipient }
				}
				change_influence = medium_influence_gain
			}
			else_if = {
				limit = {
					scope:target = { is_shunned_for = scope:recipient }
				}
				change_influence = minor_influence_gain
			}
			else = { change_influence = miniscule_influence_gain  }
		}
		stress_impact = {
			compassionate = medium_stress_impact_gain
			trusting = medium_stress_impact_gain
			honest = minor_stress_impact_gain
			just = minor_stress_impact_gain
			forgiving = minor_stress_impact_gain
		}
	}
	scope:target = {
		if = {
			limit = {
				exists = var:promised_not_to_reveal
				var:promised_not_to_reveal = scope:actor
			}
			scope:recipient = {
				add_opinion = {
					target = scope:actor
					modifier = broke_promise
				}
			}
		}
	}
	scope:recipient = { #Nudge towards rivalry
		if = {
			limit = {
				NOR = {
					has_relation_rival = scope:actor
					has_relation_potential_rival = scope:actor
				}
			}
			set_relation_potential_rival = scope:actor
		}
	}
}

torture_blind_castrate_disfigure_opinion_effect = {
	scope:recipient = {
		add_opinion = {
			modifier = $VERB$_me
			target = scope:actor
		}

		if = {
			limit = {
				exists = primary_spouse
				primary_spouse = { is_alive = yes }
				NOT = { primary_spouse = { this = scope:actor } }
			}
			primary_spouse = { add_to_list = family_of_tortured }
		}
		every_close_family_member = {
			limit = { NOT = { this = scope:actor } }
			add_to_list = family_of_tortured
		}
		if = {
			limit = {
				any_in_list = {
					list = family_of_tortured
					count = 1
					always = yes
				}
			}
			every_in_list = {
				list = family_of_tortured
				add_opinion = {
					target = scope:actor
					modifier = $VERB$_family_member
				}
			}
		}
		else_if = {
			limit = {
				any_in_list = {
					list = family_of_tortured
					count > 1
					always = yes
				}
			}
			every_in_list = {
				list = family_of_tortured
				custom = all_close_family_and_spouses
				add_opinion = {
					target = scope:actor
					modifier = $VERB$_family_member
				}
			}
		}
	}
}


torture_interaction_actor_effect = {
	scope:actor = {
		###SECRETS###
		custom_tooltip = torture_interaction_actor_effects.secrets.tt


		###STRESS###

		#Stress loss if they are my rival I hate them
		if = {
			limit = { has_relation_rival = scope:recipient }

			if = {
				limit = {
					NOR = {
						has_trait = sadistic
						has_trait = vengeful
						has_trait = compassionate
						has_trait = forgiving
					}
				}
				add_stress = medium_stress_loss
			}
			else = {
				stress_impact = {
					sadistic = major_stress_impact_loss
					vengeful = massive_stress_impact_loss
					compassionate = minor_stress_impact_gain
					forgiving = minor_stress_impact_gain
				}
			}
		}
		else_if = { # Torturing infidels is relaxing
			limit = {
				has_trait = zealous
				NOT = { scope:actor.faith = scope:recipient.faith }
			}

			if = {
				limit = {
					NOR = {
						has_trait = sadistic
						has_trait = compassionate
						has_trait = forgiving
					}
				}
				add_stress = medium_stress_loss
			}
			else = {
				stress_impact = {
					sadistic = major_stress_impact_loss
					compassionate = minor_stress_impact_gain
					forgiving = minor_stress_impact_gain
				}
			}
		}
		else_if = {
			limit = {
				NOT = {
					has_trait = sadistic
				}
				scope:recipient = {
					OR = {
						is_child_of = scope:actor
						is_grandchild_of = scope:actor
						is_great_grandchild_of = scope:actor
					}
				}
			}
			stress_impact = {
				base = medium_stress_impact_loss
				compassionate = massive_stress_impact_gain
				craven = major_stress_impact_gain
				just = medium_stress_impact_gain
				forgiving = major_stress_impact_gain
				generous = medium_stress_impact_gain
				trusting = minor_stress_impact_gain
				content = minor_stress_impact_gain
				family_first = minor_stress_impact_gain
			}
		}
		else = {
			stress_impact = {
				sadistic = medium_stress_impact_loss
				compassionate = major_stress_impact_gain
				craven = major_stress_impact_gain
				just = medium_stress_impact_gain
				forgiving = medium_stress_impact_gain
				generous = medium_stress_impact_gain
				trusting = minor_stress_impact_gain
				content = minor_stress_impact_gain
			}
		}

		###DREAD###
		if = {
			limit = {
				scope:recipient = {
					OR = {
						is_powerful_vassal_of = scope:actor # Is your powerful vassal
						AND = { # Is an Emperor
							exists = primary_title
							primary_title.tier >= tier_empire
						}
						target_is_vassal_or_below = scope:actor # Your liege/s
						scope:actor.faith.religious_head = scope:recipient # Your head of faith
					}
				}
			}
			add_dread = torture_interaction_massive_dread_gain
		}
		else_if = {
			limit = {
				scope:recipient = {
					OR = {
						AND = { # Is your vassal, and higher than Baron
							is_vassal_of = scope:actor
							primary_title.tier > tier_barony
						}
						AND = { # Is a King
							exists = primary_title
							primary_title.tier >= tier_kingdom
						}
					}
				}
			}
			add_dread = torture_interaction_major_dread_gain
		}
		else_if = {
			limit = {
				scope:recipient = {
					OR = {
						scope:actor = { # Torturing close family of your vassals is dreadful...
							any_vassal = {
								is_close_family_of = scope:recipient
							}
						}
						scope:actor = { # Torturing close family of your liege/s is the same...
							any_liege_or_above = {
								is_close_family_of = scope:recipient
							}
						}
						AND = { # Peer Vassals
							exists = primary_title
							primary_title.tier > tier_barony
							exists = liege
							liege = scope:actor.liege
						}
						AND = { # Is a Duke
							exists = primary_title
							primary_title.tier >= tier_duchy
						}
					}
				}
			}
			add_dread = torture_interaction_medium_dread_gain
		}
		else_if = {
			limit = {
				scope:recipient = {
					OR = {
						is_spouse_of = scope:actor # Your own spouse
						is_close_or_extended_family_of = scope:actor # Your own family
						AND = {
							exists = primary_title
							primary_title.tier >= tier_county # Is a Count
						}
						scope:actor = { # Torturing extended family of your vassals is dreadful...
							any_vassal = {
								is_extended_family_of = scope:recipient
							}
						}
						scope:actor = { # Torturing extended family of your liege/s is the same...
							any_liege_or_above = {
								is_extended_family_of = scope:recipient
							}
						}
					}
				}
			}
			add_dread = torture_interaction_minor_dread_gain
		}


		###OPINIONS###
		torture_blind_castrate_disfigure_opinion_effect = { VERB = tortured }

		###CHURCH OPINION & PIETY###
		if = {
			limit = {
				NOR = {
					faith = { has_doctrine = tenet_exaltation_of_pain }

					# Divine Retribution cancels out faith-based penalties
					has_perk = divine_retribution_perk
				}
			}
			add_piety = medium_piety_loss

			if = {
				limit = {
					any_learning_councillor = {
						opinion = {
							target = scope:recipient
							value >= neutral_opinion
						}
					}
				}
				random_learning_councillor = {
					add_opinion = {
						modifier = impious_opinion
						opinion = -10
						target = scope:actor
					}
				}
			}
		}
		else_if = {
			limit = {
				faith = { has_doctrine = tenet_exaltation_of_pain }
			}
			add_piety = medium_piety_gain
		}
	}
}

torturer_interaction_recipient_effect = {
	scope:recipient = {
		add_character_modifier = {
			modifier = recently_tortured
			years = 5
		}

		# Poetry does not cause lunacy.
		if = {
			limit = {
				NOT = { scope:torture_method = flag:poetry }
			}
			random = {
				chance = 5
				modifier = {
					scope:actor = { has_trait = torturer }
					add = 10
				}
				add_trait = lunatic_1
			}
		}

		if = {
			limit = {
				NOR = {
					has_trait = craven
					has_trait = brave
				}
			}
			add_stress = massive_stress_impact_gain
		}
		else = {
			stress_impact = {
				craven = monumental_stress_gain
				brave = medium_stress_impact_gain
			}
		}

		if = { # Remove the flag blocking other prison interactions
			limit = { has_character_flag = is_being_tortured }
			remove_character_flag = is_being_tortured
		}
	}
}

illegal_imprisonment_dread_effect = {
	###DREAD###
	scope:actor = {
		if = {
			limit = {
				NOT = {
					has_imprisonment_reason = scope:recipient
				}
			}
			if = {
				limit = {
					OR = {
						is_spouse_of = scope:recipient
						is_close_family_of = scope:recipient
						scope:recipient = { tier_or_related_liege_tier_greater_or_equal_trigger = { TIER = tier_kingdom } }
					}
				}
				add_dread = medium_dread_gain
			}
			else_if = {
				limit = {
					OR = {
						scope:recipient = { tier_or_related_liege_tier_equal_trigger = { TIER = tier_duchy } }
						scope:recipient = { tier_or_related_liege_tier_equal_trigger = { TIER = tier_county } }
					}
				}
				add_dread = minor_dread_gain
			}
		}
	}
}

blind_castrate_and_disfigure_effect = {
	###STRESS##
	scope:actor = {
		if = {
			limit = { has_relation_rival = scope:recipient }

			if = {
				limit = {
					NOR = {
						has_trait = sadistic #Extra stress
						has_trait = vengeful #Extra stress
						has_trait = compassionate #Lessened impact
						has_trait = forgiving #Lessened impact
					}
				}
				add_stress = medium_stress_loss
			}
			else = {
				stress_impact = {
					sadistic = major_stress_impact_loss
					vengeful = major_stress_impact_loss
					compassionate = minor_stress_impact_gain
					forgiving = minor_stress_impact_gain
				}
			}
		}
		#Regular stress
		else = {
			stress_impact = {
				sadistic = minor_stress_impact_loss
				compassionate = massive_stress_impact_gain
				craven = major_stress_impact_gain
				just = medium_stress_impact_gain
				forgiving = medium_stress_impact_gain
				generous = medium_stress_impact_gain
				trusting = minor_stress_impact_gain
				gregarious = minor_stress_impact_gain
				calm = minor_stress_impact_gain
				content = minor_stress_impact_gain
				honest = minor_stress_impact_gain
			}
		}

		###DREAD###
		if = {
			limit = {
				OR = {
					is_spouse_of = scope:recipient
					is_close_family_of = scope:recipient
					scope:recipient = { tier_or_related_liege_tier_greater_or_equal_trigger = { TIER = tier_kingdom } } #Kingdom & empire
				}
			}
			add_dread = major_dread_gain
		}
		else_if = {
			limit = {
				OR = {
					scope:recipient = { tier_or_related_liege_tier_equal_trigger = { TIER = tier_duchy } }
					scope:recipient = { tier_or_related_liege_tier_equal_trigger = { TIER = tier_county } }
				}
			}
			add_dread = medium_dread_gain
		}
		else = {
			add_dread = minor_dread_gain
		}
	}
}

blind_opinion_effect = {
	###OPINIONS###
	scope:recipient = {
		add_opinion = {
			modifier = blinded_me
			target = scope:actor
		}

		if = {
			limit = {
				exists = primary_spouse
				NOT = { primary_spouse = { this = scope:actor } }
			}
			primary_spouse = { add_to_list = family_of_blinded }
		}
		every_close_family_member = {
			limit = { NOT = { this = scope:actor } }
			add_to_list = family_of_blinded
		}
		if = {
			limit = {
				any_in_list = {
					list = family_of_blinded
					count = 1
					always = yes
				}
			}
			every_in_list = {
				list = family_of_blinded
				add_opinion = {
					target = scope:actor
					modifier = blinded_family_member
				}
			}
		}
		else_if = {
			limit = {
				any_in_list = {
					list = family_of_blinded
					count > 1
					always = yes
				}
			}
			every_in_list = {
				list = family_of_blinded
				custom = all_close_family_and_spouses
				add_opinion = {
					target = scope:actor
					modifier = blinded_family_member
				}
			}
		}
	}
}

blind_castrated_disfigured_recipient_support_effect = { #To be used in other effects
	random = {
		chance = 5
		add_trait = lunatic_1
	}

	if = {
		limit = {
			NOR = {
				has_trait = craven
				has_trait = brave
			}
		}
		add_stress = major_stress_impact_gain
	}
	else = {
		stress_impact = {
			craven = massive_stress_gain
			brave = medium_stress_impact_gain
		}
	}
	add_character_flag = { #TO make sure that they don't get spammed about the release
		flag = block_for_prison_release_notification
		days = 2
	}

	release_from_prison = yes

	if = { # Remove the flag blocking other prison interactions
		limit = { has_character_flag = is_being_tortured }
		remove_character_flag = is_being_tortured
	}
}

blind_recipient_effect = {
	scope:recipient = {
		if = {
			limit = { scope:actor = { is_ai = no } }
			add_trait_force_tooltip = blind #This is because we want to show a blinded portrait it prison.1020 for players, then we add the trait in the immediate but we still want a tooltip
		}
		else = {
			add_trait = blind
		}

		add_character_modifier = {
			modifier = recently_blinded
			years = 1
		}
		blind_castrated_disfigured_recipient_support_effect = yes
	}
}

castrate_recipient_effect = {
	scope:recipient = {
		if = {
			limit = {
				age < 12
			}
			ep3_child_castration_effect = yes
		}
		else = {
			ep3_youth_castration_effect = yes
		}


		blind_castrated_disfigured_recipient_support_effect = yes
	}
}

disfigure_recipient_effect = {
	scope:recipient = {
		if = {
			limit = { scope:actor = { is_ai = no } }
			#This is because we want to show a blinded portrait it prison.1030 for players, then we add the trait in the immediate but we still want a tooltip
			add_trait_force_tooltip = disfigured
		}
		else = {
			add_trait = disfigured
		}

		add_character_modifier = {
			modifier = recently_disfigured
			years = 1
		}
		blind_castrated_disfigured_recipient_support_effect = yes
	}
}

maimed_recipient_effect = {
	scope:recipient = {
		if = {
			limit = { scope:maim_type = flag:arm }
			if = {
				limit = { scope:actor = { is_ai = no } }
				#This is because we want to show a blinded portrait it prison.1030 for players, then we add the trait in the immediate but we still want a tooltip
				apply_maimed_trait_and_modifier_effect = yes
			}
			else = { apply_maimed_trait_and_modifier_effect = yes }
		}
		else_if = {
			limit = { scope:maim_type = flag:leg }
			if = {
				limit = { scope:actor = { is_ai = no } }
				#This is because we want to show a blinded portrait it prison.1030 for players, then we add the trait in the immediate but we still want a tooltip
				add_trait_force_tooltip = one_legged
			}
			else = { add_trait = one_legged }
			add_character_modifier = {
				modifier = recently_maimed_modifier
				years = 1
			}
		}
		blind_castrated_disfigured_recipient_support_effect = yes
	}
}


war_for_imprison_effect = {
	scope:recipient = {
		save_scope_value_as = {
			name = war_for_imprisonment_flavour
			value = yes
		}
		start_war = {
			casus_belli = refused_liege_demand_war
			target = scope:actor
		}
	}
	if = {
		limit = {
			scope:actor = { NOT = { has_imprisonment_reason = scope:recipient } }
		}
		scope:actor = {
			every_vassal = { #Vassals joining the rebel.
				limit = {
					NOR = {
						this = scope:recipient
						is_ai = no
						has_trait = incapable
						is_imprisoned = yes
						dread_modified_ai_boldness = { #Too scared to do anything.
							dreaded_character = scope:actor
							value <= -50
						}
						is_at_war_with = scope:recipient
						is_at_war_with = scope:actor
					}
					highest_held_title_tier > tier_barony
					OR = {
						#Lovers and friends always back rebel (unless also lovers/friends of the liege)
						AND = {
							OR = {
								has_relation_lover = scope:recipient
								has_relation_friend = scope:recipient
							}
							NOR = {
								has_relation_lover = scope:actor
								has_relation_friend = scope:actor
							}
						}
						#Vassals that either like recipient or have high honor will rally if the liege is being tyrannical.
						AND = {
							OR = {
								ai_honor >= 25
								opinion = {
									target = scope:recipient
									value >= 40
								}
								AND = {
									has_game_rule = hard_difficulty
									scope:actor = { is_ai = no }
									opinion = {
										target = scope:recipient
										value >= 20
									}
								}
								AND = {
									has_game_rule = very_hard_difficulty
									scope:actor = { is_ai = no }
									opinion = {
										target = scope:recipient
										value >= 0
									}
								}
							}
							NOT = {
								scope:actor = {
									has_imprisonment_reason = scope:recipient
								}
							}
						}
						#And finally, vassals that really hate their liege will join regardless (provided that they also do not hate recipient).
						AND = {
							OR = {
								opinion = {
									target = scope:recipient
									value >= -25
								}
								AND = {
									has_game_rule = hard_difficulty
									scope:actor = { is_ai = no }
									opinion = {
										target = scope:recipient
										value >= -50
									}
								}
								AND = {
									has_game_rule = very_hard_difficulty
									scope:actor = { is_ai = no }
									opinion = {
										target = scope:recipient
										value >= -75
									}
								}
							}
							OR = {
								opinion = {
									target = scope:actor
									value <= -40
								}
								AND = {
									has_game_rule = hard_difficulty
									scope:actor = { is_ai = no }
									opinion = {
										target = scope:actor
										value <= -20
									}
								}
								AND = {
									has_game_rule = very_hard_difficulty
									scope:actor = { is_ai = no }
									opinion = {
										target = scope:actor
										value <= 0
									}
								}
							}
						}
					}
				}
				add_to_list = joining_vassals
			}
			every_in_list = {
				list = joining_vassals
				save_scope_as = joining_vassal
				custom_tooltip = tooltip_fellow_vassal_joins_war #The war has not started when viewing the interaction screen.
				hidden_effect = {
					scope:recipient = {
						every_character_war = {
							limit = {
								using_cb = refused_liege_demand_war
								casus_belli = {
									primary_attacker = scope:recipient
									primary_defender = scope:actor
								}
							}
								add_to_list = war_to_join
						}
					}
					every_in_list = {
						list = war_to_join
						limit = {
							NOT = { is_defender = prev }
						}
						hidden_effect = {
							set_called_to = prev
						}
						add_attacker = prev
					}
				}
				hidden_effect = {
					scope:actor = {
						add_opinion = {
							target = prev
							modifier = rebellious_vassal_opinion
						}
					}
				}
			}
			every_vassal = {
				limit = {
					is_ai = no
					NOT = { this = scope:recipient }
					is_imprisoned = no
				}
				trigger_event = char_interaction.0232
			}
		}
	}
	scope:recipient = {
		add_opinion = {
			target = scope:actor
			modifier = attempted_arrest_opinion
		}
	}
}

vassal_revocation_tyranny_effect = { #Despite its name this is referenced when _retracting_ vassals.
	if = {
		limit = { exists = scope:use_strife_not_tyranny }
		# If you have revocation reason, we allow that.
		if = {
			limit = { has_revoke_title_reason = scope:recipient }
			consume_revoke_title_reason = scope:recipient
		}
		else_if = { #Admin liege revoking from admin vassal
			limit = {
				government_allows = administrative
				scope:recipient = {
				 	government_allows = administrative
				}
			}
		}
		else = { change_strife_opinion = major_strife_gain }
	}
	else_if = {
		limit = {
			vassal_revocation_is_tyrannical_trigger = { VASSAL = scope:recipient }
		}
		# Special Legitimacy loss if you're revoking without a reason
		if = {
			limit = { has_legitimacy = yes }
			add_legitimacy = minor_legitimacy_loss
		}
		add_tyranny = {
			value = revoke_vassal_tyranny_gain
			if = {
				limit = {
					scope:recipient = {
						is_imprisoned = yes
						NOT = { is_imprisoned_by = scope:actor }
					}
					NOT = {
						scope:actor = { has_revoke_title_reason = scope:recipient }
					}
				}
				multiply = 2
			}
		}
	}
	else_if = {
		limit = {
			has_revoke_title_reason = scope:recipient
		}
		custom_tooltip = IS_ALLOWED_TO_REVOKE_VASSAL_DESC
	}
	else_if = {
		limit = {
			faith = {
				OR = {
					has_doctrine_parameter = pluralism_righteous_revocation_tyranny_reduced
					has_doctrine_parameter = pluralism_fundamentalist_revocation_tyranny_minimal
				}
				faith_hostility_level = {
					target = scope:recipient.faith
					value >= faith_hostile_level
				}
			}
		}
		if = {
			limit = {
				faith = {
					has_doctrine_parameter = pluralism_fundamentalist_revocation_tyranny_minimal
					faith_hostility_level = {
						target = scope:recipient.faith
						value = faith_hostile_level
					}
				}
			}
			custom_tooltip = IS_ALLOWED_TO_REVOKE_HOSTILE_INFIDEL_VASSAL
		}
		else = {
			custom_tooltip = IS_ALLOWED_TO_REVOKE_EVIL_INFIDEL_VASSAL
		}
		every_vassal = {
			limit = {
				faith = scope:recipient.faith
			}
			custom = INFIDEL_REVOCATION_OPINION
			add_opinion = {
				modifier = angry_opinion
				target = scope:actor
				opinion = {
					value = revoke_vassal_tyranny_gain
					multiply = -1
				}
			}
		}
	}
}

revocation_tyranny_effect = {
	save_scope_as = liege_temp_scope
	if = {
		limit = { exists = scope:use_strife_not_tyranny }
		# If you have revocation reason, we allow that.
		if = {
			limit = { has_revoke_title_reason = $VASSAL$ }
			consume_revoke_title_reason = $VASSAL$
		}
		else = { change_strife_opinion = major_strife_gain }
	}
	else_if = {
		limit = {
			title_revocation_is_tyrannical_trigger = { VASSAL = $VASSAL$ }
		}
		add_tyranny = revoke_title_tyranny_gain
		# Special Legitimacy loss if you're revoking without a reason
		if = {
			limit = {
				has_legitimacy = yes
				NOT = {
					scope:landed_title ?= {
						duchy = scope:liege_temp_scope.capital_county.duchy
					}
				}
			}
			add_legitimacy = medium_legitimacy_loss
		}

		#If my culture is different from the recipients
		if = {
			limit = {
				NOT = { culture = $VASSAL$.culture }
			}
			$VASSAL$.culture = {
				change_cultural_acceptance = {
					target = scope:liege_temp_scope.culture
					value = revoke_title_culture_acceptance_impact
					desc = cultural_acceptance_loss_revokation
				}
			}
		}
	}
	else = {
		if = {
			limit = {
				title_revocation_is_admin_governor_trigger = { VASSAL = $VASSAL$ }
			}
			custom_description = {
				text = IS_ALLOWED_TO_REVOKE_ADMIN_GOVERNMENT
				subject = scope:liege_temp_scope
				object = $VASSAL$
			}
		}
		else_if = {
			limit = {
				exists = scope:landed_title
				has_claim_on = scope:landed_title
			}
			custom_tooltip = IS_ALLOWED_TO_REVOKE_TITLE_FOR_CLAIM_DESC
		}
		else_if = {
			limit = {
				has_revoke_title_reason = scope:recipient
			}
			custom_tooltip = IS_ALLOWED_TO_REVOKE_TITLE_DESC
		}
		else_if = {
			limit = {
				faith = {
					OR = {
						has_doctrine_parameter = pluralism_righteous_revocation_tyranny_reduced
						has_doctrine_parameter = pluralism_fundamentalist_revocation_tyranny_minimal
					}
					faith_hostility_level = {
						target = scope:recipient.faith
						value >= faith_hostile_level
					}
				}
			}
			if = {
				limit = {
					faith = {
						has_doctrine_parameter = pluralism_fundamentalist_revocation_tyranny_minimal
						faith_hostility_level = {
							target = scope:recipient.faith
							value = faith_hostile_level
						}
					}
				}
				custom_tooltip = IS_ALLOWED_TO_REVOKE_HOSTILE_INFIDEL_TITLE
			}
			else = {
				custom_tooltip = IS_ALLOWED_TO_REVOKE_EVIL_INFIDEL_TITLE
			}
			every_vassal = {
				limit = {
					faith = scope:recipient.faith
				}
				custom = INFIDEL_REVOCATION_OPINION
				add_opinion = {
					modifier = angry_opinion
					target = scope:actor
					opinion = {
						value = revoke_title_tyranny_gain
						multiply = -1
					}
				}
			}
		}
	}
}

war_for_revoke_effect = {
	$REBEL$ = {
		save_scope_value_as = {
			name = war_for_revocation_flavour
			value = yes
		}
		start_war = {
			casus_belli = refused_liege_demand_war
			target = $LIEGE$
		}
	}
	$LIEGE$ = {
		if = {
			limit = {
				NOT = { has_revoke_title_reason = $REBEL$ }
			}
			every_vassal = { #Vassals joining the rebel.
				custom = vassals_joining_war_tt
				limit = {
					NOR = {
						this = $REBEL$
						is_ai = no
						has_trait = incapable
						is_imprisoned = yes
						dread_modified_ai_boldness = { #Too scared to do anything.
							dreaded_character = $LIEGE$
							value <= -50
						}
						opinion = { # People who really, really like you will still back you
							target = $LIEGE$
							value >= 80
						}
						is_at_war_with = $REBEL$
						is_at_war_with = $LIEGE$
					}
					highest_held_title_tier > tier_barony
					OR = {
						#Lovers and friends always back rebel (unless also lovers/friends of the liege)
						AND = {
							OR = {
								has_relation_lover = $REBEL$
								has_relation_friend = $REBEL$
							}
							NOR = {
								has_relation_lover = $LIEGE$
								has_relation_friend = $LIEGE$
							}
						}
						#Vassals that either like recipient or have high honor will rally if the liege is being tyrannical.
						AND = {
							# If they can't join a faction against the liege they should not revolt
							NOR = {
								has_relation_lover = $LIEGE$
								has_relation_friend = $LIEGE$
								is_allied_to = $LIEGE$
								is_primary_heir_of = $LIEGE$
								$LIEGE$ = { has_strong_hook = prev }
								has_dread_level_towards = {
									target = $LIEGE$
									level = 2
								}
							}
							OR = {
								ai_honor >= 25
								opinion = {
									target = $REBEL$
									value >= 40
								}
								AND = {
									has_game_rule = hard_difficulty
									$LIEGE$ = { is_ai = no }
									opinion = {
										target = $REBEL$
										value >= 20
									}
								}
								AND = {
									has_game_rule = very_hard_difficulty
									$LIEGE$ = { is_ai = no }
									opinion = {
										target = $REBEL$
										value >= 0
									}
								}
							}
							NOR = {
								$LIEGE$ = { has_revoke_title_reason = $REBEL$ }
								trigger_if = {
									limit = { exists = scope:landed_title }
									$LIEGE$ = { has_claim_on = scope:landed_title }
								}
								faith = {
									faith_hostility_level = {
										target = $REBEL$.faith
										value >= faith_hostile_level
									}
								}
							}
						}
						#And finally, vassals that really hate their liege will join regardless (provided that they also do not hate recipient).
						AND = {
							OR = {
								opinion = {
									target = $REBEL$
									value >= -25
								}
								AND = {
									has_game_rule = hard_difficulty
									$LIEGE$ = { is_ai = no }
									opinion = {
										target = $REBEL$
										value >= -50
									}
								}
								AND = {
									has_game_rule = very_hard_difficulty
									$LIEGE$ = { is_ai = no }
									opinion = {
										target = $REBEL$
										value >= -75
									}
								}
							}
							OR = {
								#default threshold
								opinion = {
									target = $LIEGE$
									value <= -50
								}
								AND = {
									has_game_rule = hard_difficulty
									$LIEGE$ = { is_ai = no }
									opinion = {
										target = $LIEGE$
										value <= -25
									}
								}
								AND = {
									has_game_rule = very_hard_difficulty
									$LIEGE$ = { is_ai = no }
									opinion = {
										target = $LIEGE$
										value <= 0
									}
								}
								#If tyrannical, the default threshold will be reached if at this level
								AND = {
									$LIEGE$ = {
										title_revocation_is_tyrannical_trigger = { VASSAL = $REBEL$ }
									}
									OR = {
										opinion = {
											target = $LIEGE$
											value <= -30 #revoke_title_tyranny_gain adds -20
										}
										AND = {
											has_game_rule = hard_difficulty
											$LIEGE$ = { is_ai = no }
											opinion = {
												target = $LIEGE$
												value <= -10
											}
										}
										AND = {
											has_game_rule = very_hard_difficulty
											$LIEGE$ = { is_ai = no }
											opinion = {
												target = $LIEGE$
												value <= 10
											}
										}
									}
								}
							}
						}
					}
				}
				save_scope_as = joining_vassal
				custom_tooltip = tooltip_fellow_vassal_joins_war #The war has not started when viewing the interaction screen.
				hidden_effect = {
					$REBEL$ = {
						every_character_war = {
							limit = {
								using_cb = refused_liege_demand_war
								casus_belli = {
									primary_attacker = $REBEL$
									primary_defender = $LIEGE$
								}
							}
							add_to_list = war_to_join
						}
					}
					every_in_list = {
						list = war_to_join
						limit = {
							NOT = { is_defender = prev }
						}
						hidden_effect = {
							set_called_to = prev
						}
						add_attacker = prev
					}
				}
				hidden_effect = {
					$LIEGE$ = {
						add_opinion = {
							target = prev
							modifier = rebellious_vassal_opinion
						}
					}
				}
			}
			every_vassal = {
				limit = {
					is_ai = no
					NOT = { this = $REBEL$ }
					is_imprisoned = no
				}
				$REBEL$ = { save_scope_as = recipient }
				$LIEGE$ = { save_scope_as = actor }
				trigger_event = char_interaction.0232
			}
		}
	}
	$REBEL$ = {
		add_opinion = {
			target = $LIEGE$
			modifier = attempted_arrest_opinion
		}
	}
}

war_for_retraction_effect = {
	scope:recipient = {
		save_scope_value_as = {
			name = war_for_retraction_flavour
			value = yes
		}
		start_war = {
			casus_belli = refused_liege_demand_war
			target = scope:actor
		}
	}
	scope:actor = {
		every_vassal = { #Vassals joining the rebel.
			limit = {
				NOR = {
					this = scope:recipient
					is_ai = no
					has_trait = incapable
					is_imprisoned = yes
					dread_modified_ai_boldness = { #Too scared to do anything.
						dreaded_character = scope:actor
						value <= -50
					}
					is_at_war_with = scope:recipient
					is_at_war_with = scope:actor
				}
				highest_held_title_tier > tier_barony
				OR = {
					#Lovers and friends always back rebel (unless also lovers/friends of the liege)
					AND = {
						OR = {
							has_relation_lover = scope:recipient
							has_relation_friend = scope:recipient
						}
						NOR = {
							has_relation_lover = scope:actor
							has_relation_friend = scope:actor
						}
					}
					#Vassals that either like recipient or have high honor will rally if the liege is being tyrannical (taking away de jure vassal).
					AND = {
						OR = {
							ai_honor >= 25
							opinion = {
								target = scope:recipient
								value >= 40
							}
							AND = {
								has_game_rule = hard_difficulty
								scope:actor = { is_ai = no }
								opinion = {
									target = scope:recipient
									value >= 20
								}
							}
							AND = {
								has_game_rule = very_hard_difficulty
								scope:actor = { is_ai = no }
								opinion = {
									target = scope:recipient
									value >= 0
								}
							}
						}
						scope:recipient = {
							any_held_title = {
								is_de_jure_liege_or_above_target = scope:secondary_recipient.primary_title
							}
						}
					}
					#And finally, vassals that really hate their liege will join regardless (provided that they also do not hate recipient).
					AND = {
						OR = {
							opinion = {
								target = scope:recipient
								value >= -25
							}
							AND = {
								has_game_rule = hard_difficulty
								scope:actor = { is_ai = no }
								opinion = {
									target = scope:recipient
									value >= -50
								}
							}
							AND = {
								has_game_rule = very_hard_difficulty
								scope:actor = { is_ai = no }
								opinion = {
									target = scope:recipient
									value >= -75
								}
							}
						}
						OR = {
							opinion = {
								target = scope:actor
								value <= -40
							}
							AND = {
								has_game_rule = hard_difficulty
								scope:actor = { is_ai = no }
								opinion = {
									target = scope:actor
									value <= -20
								}
							}
							AND = {
								has_game_rule = very_hard_difficulty
								scope:actor = { is_ai = no }
								opinion = {
									target = scope:actor
									value <= 0
								}
							}
						}
					}
				}
			}
			save_scope_as = joining_vassal
			custom_tooltip = tooltip_fellow_vassal_joins_war #The war has not started when viewing the interaction screen.
			hidden_effect = {
				scope:recipient = {
					every_character_war = {
						limit = {
							using_cb = refused_liege_demand_war
							casus_belli = {
								primary_attacker = scope:recipient
								primary_defender = scope:actor
							}
						}
							add_to_list = war_to_join
					}
				}
				every_in_list = {
					list = war_to_join
					limit = {
						NOT = { is_defender = prev }
					}
					hidden_effect = {
						set_called_to = prev
					}
					add_attacker = prev
				}
			}
			hidden_effect = {
				scope:actor = {
					add_opinion = {
						target = prev
						modifier = rebellious_vassal_opinion
					}
				}
			}
		}
		every_vassal = {
			limit = {
				is_ai = no
				NOT = { this = scope:recipient }
				is_imprisoned = no
			}
			trigger_event = char_interaction.0232
		}
	}
	scope:recipient = {
		add_opinion = {
			target = scope:actor
			modifier = attempted_arrest_opinion
		}
	}
}

kick_from_court_interaction_warning_tooltip_effect = {
	save_temporary_scope_as = kicked
	if = {
		limit = { is_councillor_of = scope:actor }
		custom_tooltip = kick_from_court_councillor_warning_tt
	}
	if = {
		limit = {
			any_claim = {
				useful_courtier_or_guest_claim_trigger = { RULER = scope:actor }
			}
		}
		random_claim = {
			limit = {
				useful_courtier_or_guest_claim_trigger = { RULER = scope:actor }
				tier = tier_kingdom
			}
			alternative_limit = {
				useful_courtier_or_guest_claim_trigger = { RULER = scope:actor }
				tier = tier_duchy
			}
			alternative_limit = {
				useful_courtier_or_guest_claim_trigger = { RULER = scope:actor }
				tier = tier_county
			}
			save_scope_as = kicked_claim
		}
		custom_tooltip = kick_from_court_claimant_warning_tt
	}
	if = {
		limit = { is_commanding_army = yes }
		custom_tooltip = kick_from_court_commander_warning_tt
	}
	if = {
		limit = { is_knight_of = scope:actor }
		custom_tooltip = kick_from_court_knight_warning_tt
	}
	if = {
		limit = {
			scope:kicked = {
				has_any_court_position = yes
				any_court_position_employer = { this = scope:actor }
			}
		}
		custom_tooltip = kick_from_court_holds_court_title_warning_tt
	}
}

kick_from_court_interaction_effect = {
	select_and_move_to_pool_effect = yes

	add_opinion = {
		modifier = kicked_me_from_court
		target = scope:actor
	}
	kick_from_court_interaction_warning_tooltip_effect = yes

	every_close_family_member = {
		limit = { NOT = { any_in_list = { list = kicked_relatives_list this = prev } } }
		add_to_list = kicked_relatives_list
	}

	scope:actor = {
		if = {
			limit = { is_landless_adventurer = yes }
			every_courtier = {
				limit = {
					is_adult = yes
					NOR = {
						is_close_family_of = scope:recipient
						has_any_moderate_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
					}
				}
				custom = custom.every_adult_follower
				add_opinion = {
					target = scope:actor
					modifier = kicked_follower_from_camp_opinion
					opinion = -5
				}
			}
			scope:recipient = {
				every_relation = {
					type = rival
					limit = { is_courtier_of = scope:actor }
					add_opinion = {
						target = scope:actor
						modifier = kicked_rival_from_camp_opinion
						opinion = 30
					}
				}
			}
		}
	}
}

disinherit_effect = {
	if = {
		limit = {
			is_heir_of = $DISINHERITOR$
			NOT = {
				has_trait = disputed_heritage
			}
			$DISINHERITOR$ = {
				any_vassal = {
					has_vassal_stance = courtly
				}
			}
		}
		$DISINHERITOR$ = {
			custom_tooltip = courtly_vassal_disapproves_disinheriting
			hidden_effect = {
				every_vassal = {
					limit = {
						has_vassal_stance = courtly
					}
					add_opinion = {
						target = $DISINHERITOR$
						modifier = courtly_disinherit_opinion
					}
				}
			}
		}
	}
	add_trait = disinherited
	add_opinion = {
		modifier = disinherited_opinion
		target = $DISINHERITOR$
	}
	house = {
		every_house_member = {
			limit = {
				NOT = { house = $DISINHERITOR$.house }
			}
			custom = all_house_members
			add_opinion = {
				modifier = disinherited_house_member_opinion
				target = $DISINHERITOR$
			}
		}
	}
	if = {
		limit = {
			exists = dynasty
			NOT = { $DISINHERITOR$ = dynasty.dynast }
		}
		$DISINHERITOR$.dynasty.dynast = {
			add_opinion = {
				target = $DISINHERITOR$
				modifier = fp1_usurped_my_authority_opinion
				years = 20
			}
		}
	}
	hidden_effect = { #Nudge towards rivalry
		if = {
			limit = {
				NOR = {
					has_relation_rival = $DISINHERITOR$
					has_relation_potential_rival = $DISINHERITOR$
				}
			}
			set_relation_potential_rival = $DISINHERITOR$
		}
	}
}

restore_inheritance_effect = {
	remove_trait = disinherited
	if = {
		limit = {
			has_opinion_modifier = {
				modifier = disinherited_opinion
				target = scope:actor
			}
		}
		remove_opinion = {
			modifier = disinherited_opinion
			target = scope:actor
		}
		house = {
			if = {
				limit = {
					NOT = {
						any_house_member = {
							NOT = { this = scope:recipient }
							has_opinion_modifier = {
								modifier = disinherited_opinion
								target = scope:actor
							}
						}
					}
				}
				every_house_member = {
					custom = all_house_members
					remove_opinion = {
						modifier = disinherited_house_member_opinion
						target = scope:actor
						single = yes
					}
				}
			}
		}
	}
	else = {
		if = {
			limit = {
				NOT = { this = scope:actor }
			}
			add_opinion = {
				modifier = restored_inheritance_opinion
				target = scope:actor
			}
		}
		house = {
			every_house_member = {
				limit = {
					NOT = { this = scope:recipient }
					NOT = { this = scope:actor }
				}
				custom = all_house_members
				add_opinion = {
					modifier = restored_house_member_inheritance_opinion
					target = scope:actor
				}
			}
		}
	}
	#Remove nithing status, if applicable.
	hidden_effect = {
		if = {
			limit = { has_character_modifier = nithing_fp1_modifier }
			remove_character_modifier = nithing_fp1_modifier
		}
	}
}

denounce_effect = {
	add_trait = denounced
	if = {
		limit = {
			$ACTOR$ = {
				has_hook_of_type = {
					target = $RECIPIENT$
					type = house_head_hook
				}
			}
		}
		$ACTOR$ = {
			remove_hook = {
				target = $RECIPIENT$
				type = house_head_hook
			}
		}
	}
	if = {
		limit = {
			has_opinion_modifier = {
				target = $ACTOR$
				modifier = forgave_denounced_opinion
			}
		}
		custom_tooltip = forgiven_changed_to_denounced
		hidden_effect = {
			remove_opinion = {
				target = $ACTOR$
				modifier = forgave_denounced_opinion
			}
			add_opinion = {
				modifier = denounced_opinion
				target = $ACTOR$
			}
		}
	}
	else = {
		add_opinion = {
			modifier = denounced_opinion
			target = $ACTOR$
		}
	}
	if = {
		limit = {
			NOT = { is_close_family_of = $ACTOR$ }
		}
		house = {
			every_house_member = {
				limit = {
					NOT = { house = $ACTOR$.house }
				}
				custom = all_house_members
				add_opinion = {
					modifier = denounced_house_member_opinion
					target = $ACTOR$
				}
			}
		}

	}
}

forgive_effect = {
	remove_trait = denounced
	custom_tooltip = denounced_change_to_forgiven
	hidden_effect = {
		remove_opinion = {
			target = scope:actor
			modifier = denounced_opinion
		}
		add_opinion = {
			modifier = forgave_denounced_opinion
			target = scope:actor
			opinion = -25
		}
	}
	if = {
		limit = {
			NOT = { is_close_family_of = scope:actor }
		}
		house = {
			every_house_member = {
				limit = {
					NOT = { house = scope:actor.house }
				}
				custom = all_house_members
				add_opinion = {
					modifier = forgave_house_member_opinion
					target = scope:actor
				}
			}
		}

	}
}

dynast_claim_title_effect = {
	scope:actor = {
		add_unpressed_claim = scope:target
		stress_impact = {
			content = minor_stress_impact_gain
			generous = minor_stress_impact_gain
		}
	}
	scope:recipient = {
		add_opinion = {
			target = scope:actor
			modifier = claimed_my_title_opinion
			opinion = -50
		}
	}
}

dynast_end_dynasty_wars_effect = {
	scope:actor.dynasty = {
		add_dynasty_prestige = medium_dynasty_prestige_loss
	}

	scope:recipient = {
		every_character_war = {
			limit = {
				NOT = { primary_defender = scope:actor }
				primary_attacker = scope:recipient
				primary_defender.dynasty = scope:recipient.dynasty
			}
			primary_defender = {
				trigger_event = char_interaction.0071
			}
			end_war = white_peace
		}
	}
}

educate_child_interaction_effect = {
	scope:ward = {
		# Culture/faith conversion + university gold/tooltips
		education_flags_tooltips_effect = yes
	}
	# Travel setup
	ward_depart_effect = yes
}

education_flags_tooltips_effect = {
	#Convert culture
	if = {
		limit = { always = scope:convert_culture }
		scope:ward = {
			add_character_flag = {
				flag = convert_culture
				years = 10
			}
		}
		if = {
			limit = { scope:ward.age < 11 }
			custom_description = {
				text = "educate_child_option_convert_culture_effect"
				subject = scope:ward
				object = scope:guardian.culture
			}
		}
		else_if = {
			limit = {
				scope:ward.age >= 11
				scope:ward.age < 14
			}
			custom_description = {
				text = "educate_child_option_convert_culture_likely_effect"
				subject = scope:ward
				object = scope:guardian.culture
			}
		}
		else_if = {
			limit = { scope:ward.age >= 14 }
			custom_description = {
				text = "educate_child_option_convert_culture_unlikely_effect"
				subject = scope:ward
				object = scope:guardian.culture
			}
		}
	}
	#Convert faith
	if = {
		limit = { always = scope:convert_faith }
		scope:ward = {
			add_character_flag = {
				flag = convert_faith
				years = 10
			}
		}
		if = {
			limit = { scope:ward.age < 11 }
			custom_description = {
				text = "educate_child_option_convert_faith_effect"
				subject = scope:ward
				object = scope:guardian.faith
			}
		}
		else_if = {
			limit = {
				scope:ward.age >= 11
				scope:ward.age < 14
			}
			custom_description = {
				text = "educate_child_option_convert_faith_likely_effect"
				subject = scope:ward
				object = scope:guardian.faith
			}
		}
		else_if = {
			limit = { scope:ward.age >= 14 }
			custom_description = {
				text = "educate_child_option_convert_faith_unlikely_effect"
				subject = scope:ward
				object = scope:guardian.faith
			}
		}
	}

	# Knowledge
	if = {
		limit = {
			always = scope:send_to_university
			OR = {
				scope:recipient = {
					OR = {
						any_realm_province = {
							has_university_building_trigger = yes
						}
						any_realm_county = {
							has_county_modifier = pandidakterion_university_modifier
						}
					}
				}
				scope:actor = {
					this = scope:secondary_actor
					any_realm_province = {
						has_university_building_trigger = yes
					}
				}
			}
		}
		scope:actor = {
			remove_short_term_gold = {
				value = monumental_gold_value
				if = {
					limit = { house = { has_house_modifier = ep3_eparch_university_influence_modifier } }
					multiply = {
						value = 1
						subtract = university_cost_reduction_value
					}
				}
			}
		}
		custom_tooltip = is_sent_to_university
		add_character_flag = {
			flag = studying_at_university
			years = 17
		}
	}
}

educate_child_event_effect = {
	scope:ward = {
		#Set relation and move character
		set_relation_guardian = scope:guardian

		if = {
			limit = {
				scope:guardian = { is_playable_character = yes }
				scope:ward = { is_playable_character = no }
				NOT = {
					scope:guardian = scope:ward.host
				}
			}
			visit_court_of = scope:guardian
		}
		else_if = {
			limit = {
				scope:guardian = { is_playable_character = no }
				scope:ward = { is_playable_character = yes }
				NOT = {
					scope:ward = scope:guardian.host
				}
			}
			scope:guardian = {
				visit_court_of = scope:ward
			}
		}
		else_if = {
			limit = {
				scope:guardian = { is_playable_character = no }
				scope:ward = { is_playable_character = no }
				exists = scope:guardian.host
				NOT = {
					scope:guardian.host = scope:ward.host
				}
			}
			visit_court_of = scope:guardian.host
		}
	}

	#Opinions
	guardian_add_opinion_effect = { GUARDIAN = scope:guardian WARD_LIEGE = scope:ward_liege WARD = scope:ward }
}

call_dynasty_member_to_war_interaction_effect = {
	if = {
		limit = {
			exists = scope:target
		}

		scope:target = {
			hidden_effect = {
				set_called_to = scope:recipient
			}
			if = {
				limit = {
					is_attacker = scope:actor
				}
				add_attacker = scope:recipient
			}
			else = {
				add_defender = scope:recipient
			}
		}

		scope:actor.dynasty = {
			add_dynasty_prestige = medium_dynasty_prestige_loss
		}
	}

	if = {
		limit = { always = scope:hook }
		scope:actor = {
			use_hook = scope:recipient
		}
	}
}

offer_vassalization_interaction_effect = {
	create_title_and_vassal_change = {
		type = swear_fealty
		save_scope_as = change
	}
	scope:recipient = {
		change_liege = {
			liege = scope:actor
			change = scope:change
		}
		add_opinion = {
			modifier = became_vassal
			target = scope:actor
			opinion = 10
		}
	}
	resolve_title_and_vassal_change = scope:change

	# Special terms for feudal contracts
	scope:recipient = {
		if = {
			limit = {
				government_has_flag = government_is_feudal
			}
			if = {
				limit = { scope:high_obligations = yes }
				hidden_effect = {
					if = {
						limit = { is_independent_ruler = no } # To avoid errors during tooltip generation (prior to the contract being generated)
						vassal_contract_set_obligation_level = { type = feudal_government_taxes level = 3 }
						vassal_contract_set_obligation_level = { type = feudal_government_levies level = 3 }
					}
				}
				custom_tooltip = high_obligations_taxes
				custom_tooltip = high_obligations_levies
			}
			else_if = {
				limit = { scope:low_obligations = yes }
				hidden_effect = {
					if = {
						limit = { is_independent_ruler = no } # To avoid errors during tooltip generation (prior to the contract being generated)
						vassal_contract_set_obligation_level = { type = feudal_government_taxes level = 1 }
						vassal_contract_set_obligation_level = { type = feudal_government_levies level = 1 }
					}
				}
				custom_tooltip = low_obligations_taxes
				custom_tooltip = low_obligations_levies
			}
			else_if = {
				limit = { scope:religious_exemption = yes }
				hidden_effect = {
					if = {
						limit = { is_independent_ruler = no } # To avoid errors during tooltip generation (prior to the contract being generated)
						vassal_contract_set_obligation_level = { type = feudal_government_taxes level = 2 }
						vassal_contract_set_obligation_level = { type = feudal_government_levies level = 1 }
						vassal_contract_set_obligation_level = { type = religious_rights level = 1 }
					}
				}
				custom_tooltip = normal_obligations_taxes
				custom_tooltip = low_obligations_levies
				custom_tooltip = religious_protection_tt
			}
			else = {
				hidden_effect = {
					if = {
						limit = { is_independent_ruler = no } # To avoid errors during tooltip generation (prior to the contract being generated)
						vassal_contract_set_obligation_level = { type = feudal_government_taxes level = 2 }
						vassal_contract_set_obligation_level = { type = feudal_government_levies level = 2 }
					}
				}
				custom_tooltip = normal_obligations_taxes
				custom_tooltip = normal_obligations_levies
			}
		}
		else_if = {
			limit = {
				government_has_flag = government_is_clan
				scope:religious_exemption_clan = yes
			}
			hidden_effect = {
				if = {
					limit = { is_independent_ruler = no } # To avoid errors during tooltip generation (prior to the contract being generated)
					vassal_contract_set_obligation_level = { type = religious_rights level = 1 }
				}
			}
			custom_tooltip = religious_protection_tt
		}
	}

	# Struggle catalysts.
	hidden_effect = {
		fp3_struggle_apply_independent_vassalage_catalyst_effect = {
			NEW_LIEGE = scope:actor
			NEW_VASSAL = scope:recipient
		}
	}
}

# Effect to start a tributary relationship from a war
# $TRIBUTARY$ = the new tributary
# $SUZERAIN$ = their suzerain
# $WAR$ = required war scope
start_tributary_from_war_effect = {
	$WAR$ ?= { save_scope_as = tributary_war }
	if = {
		limit = { NOT = { exists = $WAR$ } }
		error_log = "Tried to call start_tributary_from_war_effect without a valid war scope!"
	}
	save_scope_value_as = {
		name = high_obligations
		value = yes
	}
	start_tributary_interaction_effect = {
		TRIBUTARY = $TRIBUTARY$
		SUZERAIN = $SUZERAIN$
	}
}

@tributary_truce_negotiated = 5
@tributary_truce_war = 15

# Effect to start a tributary relationship, can be called directly without a war or from start_tributary_from_war_effect
# $TRIBUTARY$ = the new tributary
# $SUZERAIN$ = their suzerain
start_tributary_interaction_effect = {

	# Nomadic Tributaries
	if = {
		limit = { $SUZERAIN$ = { has_government = nomad_government } }
		$TRIBUTARY$ = {
			if = {
				limit = {
					OR = {
						has_government = nomad_government
						has_government = herder_government
					}
				}
				start_tributary = {
					contract_group = tributary_nomadic
					suzerain = $SUZERAIN$
				}
			}
			else = {
				start_tributary = {
					contract_group = tributary_settled
					suzerain = $SUZERAIN$
				}
			}

			# Special terms depending on which options were set
			if = { # settled tributary
				limit = {
					NOR = {
						has_government = nomad_government
						has_government = herder_government
					}
				}
				if = {
					limit = { 
						OR = {
							scope:high_obligations ?= yes
							exists = scope:tributary_war
						}
					}
					if = {
						limit = { is_tributary = yes } # suppress error logging
						hidden_effect = {
							tributary_contract_set_obligation_level = { type = default_tributary_taxes level = 2 }
							tributary_contract_set_obligation_level = { type = default_tributary_levies level = 2 }
							tributary_contract_set_obligation_level = { type = default_tributary_prestige level = 2 }
						}
					}
					custom_tooltip = high_tribute_taxes
					custom_tooltip = high_tribute_levies
					custom_tooltip = high_tribute_prestige
				}
				else_if = {
					limit = { scope:low_obligations ?= yes }
					if = {
						limit = { is_tributary = yes } # suppress error logging
						hidden_effect = {
							tributary_contract_set_obligation_level = { type = default_tributary_taxes level = 0 }
							tributary_contract_set_obligation_level = { type = default_tributary_levies level = 0 }
							tributary_contract_set_obligation_level = { type = default_tributary_prestige level = 0 }
						}
					}
					custom_tooltip = low_tribute_taxes
					custom_tooltip = low_tribute_levies
					custom_tooltip = none_tribute_prestige
				}
				else = {
					if = {
						limit = { is_tributary = yes } # suppress error logging
						hidden_effect = {
							tributary_contract_set_obligation_level = { type = default_tributary_taxes level = 1 }
							tributary_contract_set_obligation_level = { type = default_tributary_levies level = 1 }
							tributary_contract_set_obligation_level = { type = default_tributary_prestige level = 1 }
						}
					}
					custom_tooltip = normal_tribute_taxes
					custom_tooltip = normal_tribute_levies
					custom_tooltip = normal_tribute_prestige
				}
			}
			else = { # nomadic tributary
				if = {
					limit = { 
						OR = {
							scope:high_obligations ?= yes
							exists = scope:tributary_war
						}
					}
					if = {
						limit = { is_tributary = yes } # suppress error logging
						hidden_effect = {
							tributary_contract_set_obligation_level = { type = nomad_government_herd level = 3 } #herd_tax_high
							tributary_contract_set_obligation_level = { type = nomad_government_prestige level = 2 }
						}
					}
					custom_tooltip = high_tribute_herd
					custom_tooltip = high_tribute_prestige
				}
				else_if = {
					limit = { scope:low_obligations ?= yes }
					if = {
						limit = { is_tributary = yes } # suppress error logging
						hidden_effect = {
							tributary_contract_set_obligation_level = { type = nomad_government_herd level = 1 } #herd_tax_low
							tributary_contract_set_obligation_level = { type = nomad_government_prestige level = 0 }
						}
					}
					custom_tooltip = low_tribute_herd
					custom_tooltip = none_tribute_prestige
				}
				else = {
					if = {
						limit = { is_tributary = yes } # suppress error logging
						hidden_effect = {
							tributary_contract_set_obligation_level = { type = nomad_government_herd level = 2 } #herd_tax_normal
							tributary_contract_set_obligation_level = { type = nomad_government_prestige level = 1 }
						}
					}
					custom_tooltip = normal_tribute_herd
					custom_tooltip = normal_tribute_prestige
				}
			}
			if = {
				limit = { is_tributary = yes } # suppress error logging
				tributary_contract_set_obligation_level = { type = suzerain_war_participation_guarantee level = 0 }
				tributary_contract_set_obligation_level = { type = tributary_war_participation_obligation level = 0 }
				custom_tooltip = no_tributary_war_obligations
				custom_tooltip = no_suzerain_guarantee
			}
		}
	}
	else = { # subjugated tributary
		$TRIBUTARY$ = {
			start_tributary = {
				contract_group = tributary_subjugated
				suzerain = $SUZERAIN$
			}
			if = {
				limit = { scope:low_obligations ?= yes }
				if = {
					limit = { is_tributary = yes } # suppress error logging
					hidden_effect = {
						tributary_contract_set_obligation_level = { type = default_tributary_taxes level = 1 }
						tributary_contract_set_obligation_level = { type = default_tributary_prestige level = 0 }
					}
				}
				custom_tooltip = low_tribute_taxes
				custom_tooltip = none_tribute_prestige
			}
			else = {
				if = {
					limit = { is_tributary = yes } # suppress error logging
					hidden_effect = {
						tributary_contract_set_obligation_level = { type = default_tributary_taxes level = 2 }
						tributary_contract_set_obligation_level = { type = default_tributary_prestige level = 1 }
					}
				}
				custom_tooltip = high_tribute_taxes
				custom_tooltip = normal_tribute_prestige
			}
			if = {
				limit = { is_tributary = yes } # suppress error logging
				hidden_effect = {
					tributary_contract_set_obligation_level = { type = suzerain_war_participation_guarantee level = 1 }
					tributary_contract_set_obligation_level = { type = tributary_war_participation_obligation level = 0 }
				}
			}
			custom_tooltip = suzerain_guarantee
			custom_tooltip = no_tributary_war_obligations
		}
	}

	# Setup truces depending on how the tributary relationship was created
	$TRIBUTARY$ = {save_scope_as = tributary_loc }
	$SUZERAIN$ = { save_scope_as = suzerain_loc }
	if = {
		limit = { exists = scope:tributary_war } # this will exist if invoked from start_tributary_from_war_effect
		$TRIBUTARY$ = {
			add_truce_one_way = {
				character = $SUZERAIN$
				years = @[tributary_truce_war]
				war = scope:tributary_war
				result = defeat
			}
		}
	}
	else = {
		$TRIBUTARY$ = {
			add_truce_both_ways = {
				character = $SUZERAIN$
				years = @[tributary_truce_negotiated]
				name = TRUCE_TRIBUTARY
			}
		}
	}
}

offer_fealty_interaction_effect = {
	create_title_and_vassal_change = {
		type = swear_fealty
		save_scope_as = change
	}
	scope:actor = {
		change_liege = {
			liege = scope:recipient
			change = scope:change
		}

		stress_impact = {
			ambitious = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
		}
	}
	resolve_title_and_vassal_change = scope:change

	scope:actor = {
		# Special terms for feudal contracts
		if = {
			limit = {
				government_has_flag = government_is_feudal
			}
			if = {
				limit = { scope:high_obligations = yes }
				hidden_effect = {
					if = {
						limit = { is_independent_ruler = no } # To avoid errors during tooltip generation (prior to the contract being generated)
						vassal_contract_set_obligation_level = { type = feudal_government_taxes level = 3 }
						vassal_contract_set_obligation_level = { type = feudal_government_levies level = 3 }
					}
				}
				custom_tooltip = high_obligations_taxes
				custom_tooltip = high_obligations_levies
			}
			else_if = {
				limit = { scope:low_obligations = yes }
				hidden_effect = {
					if = {
						limit = { is_independent_ruler = no } # To avoid errors during tooltip generation (prior to the contract being generated)
						vassal_contract_set_obligation_level = { type = feudal_government_taxes level = 1 }
						vassal_contract_set_obligation_level = { type = feudal_government_levies level = 1 }
					}
				}
				custom_tooltip = low_obligations_taxes
				custom_tooltip = low_obligations_levies
			}
			else_if = {
				limit = { scope:religious_taxation = yes }
				hidden_effect = {
					if = {
						limit = { is_independent_ruler = no } # To avoid errors during tooltip generation (prior to the contract being generated)
						vassal_contract_set_obligation_level = { type = feudal_government_taxes level = 3 }
						vassal_contract_set_obligation_level = { type = feudal_government_levies level = 2 }
						vassal_contract_set_obligation_level = { type = religious_rights level = 1 }
					}
				}
				custom_tooltip = high_obligations_taxes
				custom_tooltip = normal_obligations_levies
				if = {
					limit = { scope:recipient.faith = { has_doctrine_parameter = unlock_jizya_contract } }
					custom_tooltip = jizya_religious_protection_tt
				}
				else = { custom_tooltip = religious_protection_tt }
			}
			else = {
				hidden_effect = {
					if = {
						limit = { is_independent_ruler = no } # To avoid errors during tooltip generation (prior to the contract being generated)
						vassal_contract_set_obligation_level = { type = feudal_government_taxes level = 2 }
						vassal_contract_set_obligation_level = { type = feudal_government_levies level = 2 }
					}
				}
				custom_tooltip = normal_obligations_taxes
				custom_tooltip = normal_obligations_levies
			}
		}
		else_if = {
			limit = {
				government_has_flag = government_is_clan
				scope:religious_exemption_clan = yes
			}
			hidden_effect = {
				if = {
					limit = { is_independent_ruler = no } # To avoid errors during tooltip generation (prior to the contract being generated)
					vassal_contract_set_obligation_level = { type = religious_rights level = 1 }
				}
			}
			custom_tooltip = religious_protection_tt
		}
	}

	# Struggle catalysts.
	hidden_effect = {
		fp3_struggle_apply_independent_vassalage_catalyst_effect = {
			NEW_LIEGE = scope:recipient
			NEW_VASSAL = scope:actor
		}
	}
}


call_ally_interaction_effect = {
	if = {
		limit = {
			exists = scope:target
			scope:recipient = {
				NOR = {
					is_at_war_with = scope:target.primary_defender
					is_at_war_with = scope:target.primary_attacker
				}
			}
		}
		call_ally_interaction_event_effect = yes

	}
}

#So that we can show a tooltip in the event about them responding
call_ally_interaction_event_effect = {
	scope:target = {
		hidden_effect = {
			set_called_to = scope:recipient
		}
		if = {
			limit = {
				is_attacker = scope:actor
			}
			add_attacker = scope:recipient
			scope:actor = {
				if = {
					limit = {
						NOT = {
							has_relation_blood_brother = scope:recipient
						}
					}
					if = {
						limit = {
							scope:recipient.primary_title.tier = tier_barony
						}
						add_prestige = -10
					}
					else_if = {
						limit = {
							scope:recipient.primary_title.tier = tier_county
						}
						add_prestige = minor_prestige_loss
					}
					else_if = {
						limit = {
							scope:recipient.primary_title.tier = tier_duchy
						}
						add_prestige = medium_prestige_loss
					}
					else_if = {
						limit = {
							scope:recipient.primary_title.tier = tier_kingdom
						}
						add_prestige = major_prestige_loss
					}
					else_if = {
						limit = {
							scope:recipient.primary_title.tier = tier_empire
						}
						add_prestige = massive_prestige_loss
					}
				}
			}
		}
		else = {
			add_defender = scope:recipient
		}
	}
}

seduce_interaction_stress_effect = {
	if = {
		limit = {
			NOT = {
				scope:recipient = {
					is_consort_of = scope:actor
				}
			}
			OR = {
				scope:actor = {
					is_male = yes
					faith = { NOT = { has_doctrine_parameter = adultery_male_accepted } }
				}
				scope:actor = {
					is_female = yes
					faith = { NOT = { has_doctrine_parameter = adultery_female_accepted } }
				}
			}
		}
		scope:actor = {
			stress_impact = {
				chaste = medium_stress_impact_gain
				zealous = minor_stress_impact_gain
				honest = minor_stress_impact_gain
				just = minor_stress_impact_gain
			}
		}
	}
	else = {
		scope:actor = {
			stress_impact = {
				chaste = medium_stress_impact_gain
			}
		}
	}
}

retract_vassal_interaction_effect = {
	scope:actor = {
		vassal_revocation_tyranny_effect = yes
		if = {
			limit = {
				vassal_revocation_is_tyrannical_trigger = { VASSAL = scope:recipient }
			}
			stress_impact = {
				generous = medium_stress_impact_gain
				just = medium_stress_impact_gain
			}
		}
		else = {
			stress_impact = {
				generous = medium_stress_impact_gain
				forgiving = minor_stress_impact_gain
			}
		}
		consume_revoke_title_reason = scope:recipient
	}
	create_title_and_vassal_change = {
		type = revoked
		save_scope_as = change
		add_claim_on_loss = no
	}

	scope:secondary_recipient = {
		change_liege = {
			liege = scope:actor
			change = scope:change
		}
	}

	resolve_title_and_vassal_change = scope:change

	scope:recipient = {
		add_opinion = {
			target = scope:actor
			modifier = retracted_vassal
		}
	}
	if = {
		limit = { 
			always = scope:hook
			scope:actor ?= { has_hook = scope:recipient }
		}
		scope:actor = { use_hook = scope:recipient }
	}
}

ask_for_pardon_interaction_effect = {
	scope:actor = {
		every_liege_or_above = {
			if = {
				limit = { has_imprisonment_reason = scope:actor }
				send_interface_toast = {
					title = ask_for_pardon_interaction_accept_toast
					left_icon = scope:recipient
					consume_imprisonment_reasons = scope:actor
				}
			}
			if = {
				limit = { has_banish_reason = scope:actor }
				send_interface_toast = {
					title = ask_for_pardon_interaction_accept_toast
					left_icon = scope:recipient
					consume_banish_reasons = scope:actor
				}
			}
			if = {
				limit = { has_execute_reason = scope:actor }
				send_interface_toast = {
					title = ask_for_pardon_interaction_accept_toast
					left_icon = scope:recipient
					consume_execute_reasons = scope:actor
				}
			}
			if = {
				limit = { has_revoke_title_reason = scope:actor }
				send_interface_toast = {
					title = ask_for_pardon_interaction_accept_toast
					left_icon = scope:recipient
					consume_revoke_title_reason = scope:actor
				}
			}
		}
		stress_impact = {
			stubborn = minor_stress_impact_gain
		}
	}
	if = {
		limit = {
			always = scope:hook
			scope:actor = { # TO make sure you still have a hook on them
				has_usable_hook = scope:recipient
			}
		}
		scope:actor = {
			use_hook = scope:recipient
		}
	}
}

revoke_title_interaction_effect = {
	if = {
		limit = {
			scope:recipient = {
				faith = scope:actor.faith
				government_has_flag = government_is_theocracy
			}
			NOT = { scope:actor = scope:actor.faith.religious_head } #No loss if actor is head of faith themselves
		}
		scope:actor = {
			add_piety = major_piety_loss
		}
		if = {
			limit = {
				exists = scope:actor.faith.religious_head
			}
			scope:actor.faith.religious_head = {
				add_opinion = {
					target = scope:actor
					modifier = impious_opinion
					opinion = -20
				}
			}
		}
	}
	if = {
		limit = {
			exists = scope:actor.faith.religious_head
			scope:recipient = scope:actor.faith.religious_head
		}
		scope:actor = {
			add_piety_level = -2
		}
	}
	if = {
		limit = {
			scope:landed_title.tier != tier_barony
			scope:recipient = {
				NOT = { government_has_flag = government_is_herder }
			}
		}
		scope:actor = {
			revocation_tyranny_effect = { VASSAL = scope:recipient }
			title_revocation_stress_effect = { VASSAL = scope:recipient }
			consume_revoke_title_reason = scope:recipient
		}
		scope:recipient = {
			if = {
				limit = {
					NOT = { exists = scope:administrative_revocation }
					is_landed_or_landless_administrative = no
				}
				add_pressed_claim = scope:landed_title
			}
			if = {
				limit = {
					is_a_faction_member = yes
				}
				add_joined_faction_discontent = 25
			}
		}

		if = {
			limit = { scope:landed_title.tier = tier_county }
			scope:landed_title = {
				change_county_control = {
					value = -30
					if = {
						limit = {
							NOT = { scope:recipient.culture = scope:actor.culture }
							scope:recipient.culture = this.culture
						}
						multiply = 1.5
					}
					if = {
						limit = {
							NOT = { scope:recipient.faith = scope:actor.faith }
							scope:recipient.faith = this.faith
						}
						multiply = 1.5
					}
				}
			}
		}

		if = {
			limit = {
				scope:actor.culture = { has_cultural_parameter = penalty_for_revoking_titles_from_house_members }
				exists = scope:actor.house
				exists = scope:recipient.house
				scope:actor.house = scope:recipient.house
			}
			if = {
				limit = {
					scope:landed_title.tier = tier_county
				}
				scope:actor = {
					add_prestige = medium_prestige_loss
				}
			}
			else_if = {
				limit = {
					scope:landed_title.tier = tier_duchy
				}
				scope:actor = {
					add_prestige = major_prestige_loss
				}
			}
			else_if = { #Empire
				limit = {
					scope:landed_title.tier = tier_kingdom
				}
				scope:actor = {
					add_prestige = massive_prestige_loss
				}
			}
		}

		if = {
			limit = {
				scope:actor.culture = { has_cultural_parameter = penalty_for_revoking_titles_from_close_family }
				exists = scope:actor
				exists = scope:recipient
				scope:actor = {
					is_close_family_of = scope:recipient
				}
			}
			if = {
				limit = {
					scope:landed_title.tier = tier_county
				}
				scope:actor = {
					add_prestige = medium_prestige_loss
				}
			}
			else_if = {
				limit = {
					scope:landed_title.tier = tier_duchy
				}
				scope:actor = {
					add_prestige = major_prestige_loss
				}
			}
			else_if = { #Empire
				limit = {
					scope:landed_title.tier = tier_kingdom
				}
				scope:actor = {
					add_prestige = massive_prestige_loss
				}
			}
		}

		if = {
			limit = {
				scope:actor.culture = { has_cultural_parameter = piety_penalty_for_revoking_titles_from_house_members }
				exists = scope:actor.house
				exists = scope:recipient.house
				scope:actor.house = scope:recipient.house
			}
			if = {
				limit = {
					scope:landed_title.tier = tier_county
				}
				scope:actor = {
					add_piety = medium_piety_loss
				}
			}
			else_if = {
				limit = {
					scope:landed_title.tier = tier_duchy
				}
				scope:actor = {
					add_piety = major_piety_loss
				}
			}
			else = { #Can't revoke empire titles anyway
				limit = {
					scope:landed_title.tier = tier_kingdom
				}
				scope:actor = {
					add_piety = massive_piety_loss
				}
			}
		}
		
		# If we're a clan this interaction affects unity
		if = {
			limit = {
				scope:actor = { government_has_flag = government_is_feudal }			# Shogunate
				scope:recipient = { government_has_flag = government_is_feudal }		# Shogunate
				exists = scope:actor.house
				exists = scope:recipient.house
				scope:actor.house = scope:recipient.house
				scope:landed_title.tier >= tier_county
			}
			scope:actor.house = {
				if = {
					limit = {
						scope:landed_title.tier = tier_county
					}
					save_scope_value_as = {
						name = revoke_title_unity_loss
						value = minor_unity_loss
					}
				}
				if = {
					limit = {
						scope:landed_title.tier = tier_duchy
					}
					save_scope_value_as = {
						name = revoke_title_unity_loss
						value = medium_unity_loss
					}
				}
				else_if = {
					limit = {
						scope:landed_title.tier = tier_kingdom
					}
					save_scope_value_as = {
						name = revoke_title_unity_loss
						value = major_unity_loss
					}
				}
				if = {
					limit = { exists = scope:revoke_title_unity_loss }
					add_clan_unity_interaction_effect = {
						CHARACTER = scope:actor
						TARGET = scope:recipient
						VALUE = scope:revoke_title_unity_loss
						DESC = clan_unity_title_revoked.desc
						REVERSE_NON_HOUSE_TARGET = no
					}
				}
			}
		}
		
		# EP3 - Become Adventurer - Revocation
		scope:recipient = {
			if = {
				limit = {
					has_ep3_dlc_trigger = yes
					is_valid_for_laampdom = yes
				}
				# Plus for our memory variable.
				primary_title = { save_scope_as = lost_primary_title }
				custom_tooltip = {
					text = laamp_may_become_adventurer_tt
					trigger_event = {
						id = ep3_laamps.0041
						delayed = yes
					}
				}
			}
		}
	}
	else = {
		if = {
			limit = {
				NOT = { exists = scope:revoke_title_interaction }
			}
			custom_tooltip = IS_ALLOWED_TO_REVOKE_TITLE_BARONY_DESC
			scope:actor = {
				if = {
					limit = {
						any_vassal = {
							has_vassal_stance = barons_and_minor_landholders
						}
					}
					custom_tooltip = barons_and_minor_landholders_disapproves_baron_revocations
					hidden_effect = {
						every_vassal = {
							limit = {
								has_vassal_stance = barons_and_minor_landholders
							}
							add_opinion = {
								target = scope:actor
								modifier = barons_and_minor_landholders_disapproves_baron_revocations_opinion
							}
						}
					}
				}
			}
		}
	}


	scope:actor = {
		if = {
			limit = {
				scope:hook = yes
				scope:recipient = { is_alive = yes }
			}
			use_hook = scope:recipient
		}
		if = {
			limit = {
				scope:hook_liege ?= yes
				scope:intermediary = { is_alive = yes }
			}
			use_hook = scope:intermediary
		}
	}
	if = {
		limit = {
			scope:recipient = { government_has_flag = government_is_herder }
		}
		scope:recipient = {
			add_opinion = {
				target = scope:actor
				opinion = -10 # Herders don't care much
				modifier = revoked_title
			}
		}
	}
	else = {
		scope:recipient = {
			add_opinion = {
				target = scope:actor
				modifier = revoked_title
			}
			if = { #If they recently imprisoned you, or asked for your excommunication, they become your rival
				limit = {
					OR = {
						has_opinion_modifier = {
							target = scope:actor
							modifier = released_from_prison
						}
						AND = {
							exists = var:requested_my_excommunication
							var:requested_my_excommunication = scope:actor
						}
					}
					NOT = {
						has_relation_rival = scope:actor
					}
				}
				if = {
					limit = {
						has_relation_potential_rival = scope:actor
					}
					remove_relation_potential_rival = scope:actor
				}
				set_relation_rival = {
					target = scope:actor
					reason = rival_revoked_title_reversed
				}
			}
			else = {
				progress_towards_rival_effect = {
					CHARACTER = scope:actor
					REASON = rival_revoked_title_progress
					OPINION = 0
				}
			}
		}
	}

	# Penalty for taking the Party Baron's last title. I mean, come on...
	if = {
		limit = {
			scope:recipient = {
				has_character_flag = is_party_baron
				NOT = {
					any_held_title = {
						NOT = { this = scope:landed_title }
					}
				}
			}
		}
		scope:actor = {
			add_character_modifier = {
				modifier = party_baron_ended_the_party_modifier
				years = 10
			}
			random_owned_story = {
				limit = {
					story_type = story_party_baron
				}
				end_story = yes
			}
		}
	}
}

call_house_member_to_war_interaction_effect = {
	if = {
		limit = {
			exists = scope:target
		}

		scope:target = {
			hidden_effect = {
				set_called_to = scope:recipient
			}
			if = {
				limit = {
					is_attacker = scope:actor
				}
				add_attacker = scope:recipient
			}
			else = {
				add_defender = scope:recipient
			}
		}
	}

	if = {
		limit = { always = scope:hook }
		scope:actor = {
			use_hook = scope:recipient
		}
	}
}

sun_trial_interaction_piety_effect = {
	#Imprisoner gets piety
	add_piety = {
		value = minor_piety_value
		if = {
			limit = { has_execute_reason = scope:recipient }
			add = minor_piety_value
		}
		if = {
			limit = { has_banish_reason = scope:recipient }
			add = miniscule_piety_value
		}
		if = {
			limit = { has_revoke_title_reason = scope:recipient }
			add = miniscule_piety_value
		}
	}
}

declaration_of_repentance_interaction_effect = {
	if = {
		limit = { scope:declaration_hook = yes }
		scope:actor = {
			use_hook = scope:recipient
		}
	}

	scope:actor = {
		if = {
			limit = {
				scope:declaration_hook = no
			}
			#Lose a ton of prestige (e.g., Henry's Walk to Canossa)
			add_prestige = massive_prestige_loss
			add_prestige_level = -1
		}

		#Character cannot be excommunicated again for 10 years.
		remove_trait = excommunicated
		add_character_modifier = {
			modifier = excommunication_recently_lifted
			years = 10
		}

		stress_impact = {
			cynical = minor_stress_impact_gain
		}
	}
	scope:recipient = {
		add_prestige = major_prestige_gain
		add_opinion = {
			modifier = repentant_opinion
			target = scope:actor
			opinion = 10
		}
	}
}

seek_indulgences_interaction_effect = {
	scope:actor = {
		if = {
			limit = {
				OR = {
					has_character_flag = seek_indulgences_removed_kinslayer_3 # For the post-interaction letter event
					AND = {
						has_trait = kinslayer_3
						trait_is_shunned_or_criminal_in_faith_trigger = { FAITH = faith TRAIT = kinslayer_3 GENDER_CHARACTER = scope:actor }
					}
				}
			}
			pay_short_term_gold = {
				target = scope:recipient
				gold = seek_indulgences_major_criminal_trait_value
			}
			remove_trait_force_tooltip = kinslayer_3
			add_character_flag = {
				flag = seek_indulgences_removed_kinslayer_3
				days = 30
			}
		}
		else_if = {
			limit = {
				OR = {
					has_character_flag = seek_indulgences_removed_kinslayer_2 # For the post-interaction letter event
					AND = {
						has_trait = kinslayer_2
						trait_is_shunned_or_criminal_in_faith_trigger = { FAITH = faith TRAIT = kinslayer_2 GENDER_CHARACTER = scope:actor }
					}
				}
			}
			pay_short_term_gold = {
				target = scope:recipient
				gold = seek_indulgences_medium_criminal_trait_value
			}
			remove_trait_force_tooltip = kinslayer_2
			add_character_flag = {
				flag = seek_indulgences_removed_kinslayer_2
				days = 30
			}
		}
		else_if = {
			limit = {
				OR = {
					has_character_flag = seek_indulgences_removed_witch # For the post-interaction letter event
					AND = {
						has_trait = witch
						trait_is_shunned_or_criminal_in_faith_trigger = { FAITH = faith TRAIT = witch GENDER_CHARACTER = scope:actor }
					}
				}
			}
			pay_short_term_gold = {
				target = scope:recipient
				gold = seek_indulgences_medium_criminal_trait_value
			}
			remove_trait_force_tooltip = witch
			add_character_flag = {
				flag = seek_indulgences_removed_witch
				days = 30
			}
		}
		else_if = {
			limit = {
				OR = {
					has_character_flag = seek_indulgences_removed_deviant # For the post-interaction letter event
					AND = {
						has_trait = deviant
						trait_is_shunned_or_criminal_in_faith_trigger = { FAITH = faith TRAIT = deviant GENDER_CHARACTER = scope:actor }
					}
				}
			}
			pay_short_term_gold = {
				target = scope:recipient
				gold = seek_indulgences_medium_criminal_trait_value
			}
			remove_trait_force_tooltip = deviant
			add_character_flag = {
				flag = seek_indulgences_removed_deviant
				days = 30
			}
		}
		else_if = {
			limit = {
				OR = {
					has_character_flag = seek_indulgences_removed_sodomite # For the post-interaction letter event
					AND = {
						has_trait = sodomite
						trait_is_shunned_or_criminal_in_faith_trigger = { FAITH = faith TRAIT = sodomite GENDER_CHARACTER = scope:actor }
					}
				}
			}
			pay_short_term_gold = {
				target = scope:recipient
				gold = seek_indulgences_medium_criminal_trait_value
			}
			remove_trait_force_tooltip = sodomite
			add_character_flag = {
				flag = seek_indulgences_removed_sodomite
				days = 30
			}
		}
		else_if = {
			limit = {
				OR = {
					has_character_flag = seek_indulgences_removed_kinslayer_1 # For the post-interaction letter event
					AND = {
						has_trait = kinslayer_1
						trait_is_shunned_or_criminal_in_faith_trigger = { FAITH = faith TRAIT = kinslayer_1 GENDER_CHARACTER = scope:actor }
					}
				}
			}
			pay_short_term_gold = {
				target = scope:recipient
				gold = seek_indulgences_minor_criminal_trait_value
			}
			remove_trait_force_tooltip = kinslayer_1
			add_character_flag = {
				flag = seek_indulgences_removed_kinslayer_1
				days = 30
			}
		}
		else_if = {
			limit = {
				OR = {
					has_character_flag = seek_indulgences_removed_adulterer # For the post-interaction letter event
					AND = {
						has_trait = adulterer
						trait_is_shunned_or_criminal_in_faith_trigger = { FAITH = faith TRAIT = adulterer GENDER_CHARACTER = scope:actor }
					}
				}
			}
			pay_short_term_gold = {
				target = scope:recipient
				gold = seek_indulgences_minor_criminal_trait_value
			}
			remove_trait_force_tooltip = adulterer
			add_character_flag = {
				flag = seek_indulgences_removed_adulterer
				days = 30
			}
		}
		else_if = {
			limit = {
				OR = {
					has_character_flag = seek_indulgences_removed_fornicator # For the post-interaction letter event
					AND = {
						has_trait = fornicator
						trait_is_shunned_or_criminal_in_faith_trigger = { FAITH = faith TRAIT = fornicator GENDER_CHARACTER = scope:actor }
					}
				}
			}
			pay_short_term_gold = {
				target = scope:recipient
				gold = seek_indulgences_minor_criminal_trait_value
			}
			remove_trait_force_tooltip = fornicator
			add_character_flag = {
				flag = seek_indulgences_removed_fornicator
				days = 30
			}
		}
		else_if = {
			limit = { has_trait = gallowsbait }
			pay_short_term_gold = {
				target = scope:recipient
				gold = seek_indulgences_minor_criminal_trait_value
			}
			if = {
				limit = {
					has_trait_xp = {
						trait = gallowsbait
						track = bandit
						value >= wipe_slate_min_xp_to_remove_trait_value
					}
				}
				add_trait_xp = {
					trait = gallowsbait
					track = bandit
					value = -40
				}
			}
			else_if = {
				limit = {
					has_trait_xp = {
						trait = gallowsbait
						track = trickster
						value >= wipe_slate_min_xp_to_remove_trait_value
					}
				}
				add_trait_xp = {
					trait = gallowsbait
					track = trickster
					value = -40
				}
			}
			else_if = {
				limit = {
					has_trait_xp = {
						trait = gallowsbait
						track = thief
						value >= wipe_slate_min_xp_to_remove_trait_value
					}
				}
				add_trait_xp = {
					trait = gallowsbait
					track = thief
					value = -40
				}
			}
			else_if = {
				limit = {
					has_trait_xp = {
						trait = gallowsbait
						track = poacher
						value >= wipe_slate_min_xp_to_remove_trait_value
					}
				}
				add_trait_xp = {
					trait = gallowsbait
					track = poacher
					value = -40
				}
			}
			else_if = {
				limit = {
					has_trait_xp = {
						trait = gallowsbait
						track = marauder
						value >= wipe_slate_min_xp_to_remove_trait_value
					}
				}
				add_trait_xp = {
					trait = gallowsbait
					track = marauder
					value = -40
				}
			}
			else = { remove_trait = gallowsbait }
		}
		else = {
			pay_short_term_gold = {
				target = scope:recipient
				gold = seek_indulgences_buy_piety_value
			}
			add_piety = medium_piety_gain
		}

		reverse_add_opinion = {
			target = scope:recipient
			modifier = pleased_opinion
			opinion = 25
		}
		stress_impact = {
			greedy = minor_stress_impact_gain
			cynical = minor_stress_impact_gain
		}
	}
}

hof_ask_for_gold_interaction_effect = {
	scope:recipient = {
		pay_short_term_gold = {
			target = scope:actor
			gold = scope:actor.head_of_faith_gold_value
		}
		add_opinion = {
			target = scope:actor
			modifier = requested_money_opinion
			opinion = -20
		}
	}
	scope:actor = {
		if = {
			limit = {
				scope:hook = no
			}
			add_piety = major_piety_loss
		}
		if = {
			limit = { always = scope:hook }
			use_hook = scope:recipient
		}
		if = {
			limit = {
				any_vassal = {
					has_vassal_stance = zealot
			}
		}
		custom_tooltip = zealot_vassal_disapproves_asking_hof_for_gold
			hidden_effect = {
				every_vassal = {
					limit = {
						has_vassal_stance = zealot
					}
					add_opinion = {
						target = scope:actor
						modifier = zealot_disapproves_of_asking_hof_for_gold_opinion
					}
				}
			}
		}
	}
}

hof_ask_for_claim_interaction_effect = {
	scope:secondary_recipient = {
		add_opinion = {
			target = scope:actor
			modifier = claimed_my_title_opinion
			opinion = -50
		}
	}
	scope:actor = {
		add_piety = {
			value = claim_piety_value
			multiply = -1
		}
		if = {
			limit = { always = scope:claim_hook }
			use_hook = scope:recipient
		}
		add_pressed_claim = scope:target
	}
}

vassal_claim_liege_title_interaction_effect = {
	scope:actor = {
		add_unpressed_claim = scope:target
	}
	scope:recipient = {
		add_opinion = {
			target = scope:actor
			modifier = claimed_my_title_opinion
			opinion = -50
		}
	}
}

convert_at_war_interaction_effect = {
	scope:actor = {
		every_character_war = {
			limit = {
				primary_defender = scope:actor
				primary_attacker = scope:recipient
				using_non_ghw_holy_war_cb_trigger = yes
			}
			set_variable = {
				name = invalidate_defender_faith_change #This variable will invalidate the war and send proper invalidation message
				value = yes
			}
			show_as_tooltip = { end_war = invalidated }
		}

		set_character_faith_with_conversion = scope:recipient.faith

		add_piety = medium_piety_loss
		if = {
			limit = { NOT = { scope:recipient.faith = { has_doctrine_parameter = unreformed } } }
			add_piety_level = -3
		}
		stress_impact = {
			zealous = medium_stress_impact_gain
		}
	}
	scope:recipient = {
		add_piety_experience = major_piety_value
	}
}

demand_conversion_vassal_ruler_interaction_effect = {
	demand_conversion_interaction_effect = yes
	hidden_effect = {
		if = {
			limit = {
				exists = scope:recipient.capital_county
				scope:recipient.capital_county.faith = scope:recipient.faith
			}
			save_scope_value_as = {
				name = convert_capital
				value = yes
			}
		}
	}
	if = {
		limit = {
			scope:hook = yes
			scope:actor = { has_usable_hook = scope:recipient }
		}
		scope:actor = {
			use_hook = scope:recipient
		}
	}
	else_if = {
		limit = { scope:recipient = { is_imprisoned_by = scope:actor } }
		scope:recipient = { release_from_prison = yes }
	}
	#Negative opinions
	scope:recipient = {
		add_opinion = {
			modifier = demanded_my_conversion_opinion
			target = scope:actor
			opinion = -10
		}
	}
}

demand_conversion_player_ruler_interaction_effect = {
	demand_conversion_interaction_effect = yes

	if = {
		limit = {
			scope:demand_conversion_hook = yes
		}
		scope:actor = {
			use_hook = scope:recipient
		}
	}
}

title_revocation_stress_effect = {
	if = {
		limit = {
			title_revocation_is_tyrannical_trigger = { VASSAL = $VASSAL$ }
		}
		stress_impact = {
			generous = medium_stress_impact_gain
			just = medium_stress_impact_gain
		}
	}
	else = {
		stress_impact = {
			generous = minor_stress_impact_gain
			forgiving = minor_stress_impact_gain
		}
	}
}

revoke_holy_order_lease_effect = {
	if = {
		limit = {
			$TARGET$.faith = {
				any_faith_holy_order = {
					num_leased_titles = 1
					title = $BARONY$.lessee_title
				}
			}
		}
		custom_tooltip = destroy_holy_order_warning
	}

	$TARGET$ = {
		hidden_effect = { #Nudge towards rivalry
			if = {
				limit = {
					NOR = {
						has_relation_rival = $CHARACTER$
						has_relation_potential_rival = $CHARACTER$
					}
				}
				set_relation_potential_rival = $CHARACTER$
			}
		}

		if = {
				limit = {
					NOT = { this = $CHARACTER$ }
				}
			add_opinion = {
				target = $CHARACTER$
				modifier = angry_opinion
				opinion = -40
			}
		}

		faith = {
			if = {
				limit = {
					exists = religious_head
					NOT = { religious_head = $CHARACTER$ }
				}
				religious_head = {
					add_opinion = {
						modifier = angry_opinion
						target = $CHARACTER$
						opinion = -20
					}
					if = {
						limit = {
							has_opinion_modifier = {
								target = $CHARACTER$
								modifier = founded_holy_order_opinion
							}
						}
						remove_opinion = {
							target = $CHARACTER$
							modifier = founded_holy_order_opinion
						}
					}
				}
			}
		}
	}

	$CHARACTER$ = {
		send_interface_message = {
			type = holy_order_lease_revoked_message
			title = revoke_leased_title_interaction_notification
			right_icon = $TARGET$

			# Zealous costs stress if same-faith.
			if = {
				limit = { $CHARACTER$.faith = $TARGET$.faith }
				stress_impact = {
					zealous = massive_stress_impact_gain
					generous = medium_stress_impact_gain
					order_member = minor_stress_impact_gain
				}

				add_piety = {
					value = 0
					subtract = cancel_holy_order_piety_cost
				}
			}
			else_if = {
				# Bit less but still some if you view the other faith as astray.
				limit = {
					$CHARACTER$.faith = {
						faith_hostility_level = {
							target = $TARGET$.faith
							value <= faith_astray_level
						}
					}
				}
				stress_impact = {
					zealous = major_stress_impact_gain
					generous = medium_stress_impact_gain
				}

				add_piety = {
					value = -100
				}
			}
			else = {

				if = {
					limit = { exists =  $CHARACTER$.faith.religious_head  }
					$CHARACTER$.faith.religious_head = {
						add_opinion = {
							modifier = pleased_opinion
							target = $CHARACTER$
							opinion = 20
						}
					}
				}

				add_piety = {
					value = 250
				}

				$TARGET$.faith = {
					# Fervor impact: big as it's rare
					change_fervor = {
						value = 10
						desc = fervor_gain_holy_order_expelled_by_force
					}
				}

				# If the county has the same faith than the HO, locals are unhappy
				$BARONY$ = {
					if = {
						limit = { title_province.county.faith = $TARGET$.faith }
						title_province.county = {
							add_county_modifier = {
								modifier = lost_holy_order_modifier
								years = 10
							}
						}
					}
				}
			}

			$BARONY$ = {
				revoke_lease = yes
			}
		}
	}
}

revoke_holy_order_duel_victor_apply_effects_effect = {
	scope:sc_victor = {
		add_stress = major_stress_loss
		add_prestige = major_prestige_gain
	}
}

add_clan_unity_interaction_effect = {
	if = {
		limit = { # Check if unity is relevant
			$CHARACTER$ = { government_has_flag = government_is_feudal }		# Shogunate
			$TARGET$ = { government_has_flag = government_is_feudal }			# Shogunate
			exists = $CHARACTER$.house
			exists = $TARGET$.house
			$CHARACTER$.house = $TARGET$.house
			trigger_if = {
				limit = {
					exists = scope:actor
					exists = scope:recipient
					NOT = { scope:actor = scope:recipient }
				}
				NOT = { $CHARACTER$ = $TARGET$ } # As a safety, let's make sure that we are not interacting with ourselves
			}
		}
		
		apply_clan_unity_interaction_effect = {
			CHARACTER = $CHARACTER$
			TARGET = $TARGET$
			DESC = $DESC$
			VALUE = $VALUE$
			VALUE_REVERSED = no
		}
	}
	else_if = {
		limit = { # Only apply reversed effect for the house head to keep the gauge in check
			$REVERSE_NON_HOUSE_TARGET$ = yes

			$CHARACTER$ = { government_has_flag = government_is_feudal }		# Shogunate
			$CHARACTER$.house ?= {
				house_head = $CHARACTER$
			}
			OR = {
				AND = {
					exists = $TARGET$.house
					NOT = { $CHARACTER$.house = $TARGET$.house }
				}
				$TARGET$ = { is_lowborn = yes }
			}
		}
		apply_clan_unity_interaction_effect = {
			CHARACTER = $CHARACTER$
			TARGET = $TARGET$
			DESC = $DESC$
			VALUE = $VALUE$
			VALUE_REVERSED = yes
		}
	}
}

apply_clan_unity_interaction_effect = {
	# Save scopes for localisation
	$CHARACTER$ = { save_scope_as = unity_character }
	$TARGET$ = { save_scope_as = unity_target }

	$CHARACTER$.house = {
		save_scope_as = character_house

		add_unity_value = {
			value = {
				value = $VALUE$
				if = { # House heads have a larger impact on unity
					limit = { house_head = $CHARACTER$ }
					multiply = unity_house_head_multiplier_value
				}
				if = {
					limit = { $VALUE_REVERSED$ = yes }
					multiply = -1
				}
			}
			character = $CHARACTER$
			desc = $DESC$
		}
	}

	# Notify human players if they are not involved!
	if = {
		limit = {
			trigger_if = {
				limit = { $VALUE$ >= 0 }
				$VALUE$ >= major_unity_value
			}
			trigger_else = {
				$VALUE$ <= major_unity_value
			}
		}
		# Notify human players if they are not involved!
		notify_players_about_unity_change_effect = {
			CHARACTER = $CHARACTER$
			TARGET = $TARGET$
			DESC = $DESC$
		}
	}
}

diarch_declare_recipient_criminal_effect = {
	scope:actor = {
		# First we process the diarch.
		## Players get a different tooltip, since they don't want to see opinion.
		if = {
			limit = { is_ai = no }
			custom_tooltip = diarch_imprison_reason_for_player.tt
			hidden_effect = {
				add_opinion = {
					target = scope:recipient
					modifier = treasonous_disobeyed_diarch
				}
			}
		}
		## AI use the standard opinion flow.
		else = {
			add_opinion = {
				target = scope:recipient
				modifier = treasonous_disobeyed_diarch
			}
		}
		# Then their liege.
		liege = {
			# Same flow: players get a different tooltip so that they don't see opinion.
			if = {
				limit = { is_ai = no }
				custom_tooltip = ADD_OPINION_EFFECT_I_HAVE_IMPRISONMENT_REASON_UNUSABLE
				hidden_effect = {
					add_opinion = {
						target = scope:recipient
						modifier = treasonous_disobeyed_diarch
					}
				}
			}
			# But AI just get opinion.
			else = {
				add_opinion = {
					target = scope:recipient
					modifier = treasonous_disobeyed_diarch
				}
			}
		}
	}
}

diarch_declare_claim_war_effect = {
	start_war = {
		casus_belli = claim_cb
		target = scope:recipient
		claimant = scope:actor
		target_title = scope:landed_title
	}
}

diarch_declare_vassalisation_war_effect = {
	start_war = {
		casus_belli = diarch_vassalisation_cb
		target = scope:recipient
		target_title = scope:secondary_recipient.primary_title
	}
}

make_criminal_effect = {
	random_list = {
		10 = {
			trigger = {
				trait_is_criminal_in_faith_trigger = {
					TRAIT = adulterer
					GENDER_CHARACTER = root
					FAITH = root.faith
				}
				NOT = { has_trait = adulterer }
			}
			add_trait = adulterer
		}
		10 = {
			trigger = {
				trait_is_criminal_in_faith_trigger = {
					TRAIT = kinslayer_3
					GENDER_CHARACTER = root
					FAITH = root.faith
				}
				NOT = { has_trait = kinslayer_3 }
			}
			add_trait = kinslayer_3
		}
		10 = {
			trigger = {
				trait_is_criminal_in_faith_trigger = {
					TRAIT = witch
					GENDER_CHARACTER = root
					FAITH = root.faith
				}
				NOT = { has_trait = witch }
			}
			add_trait = witch
		}
		10 = {
			trigger = {
				trait_is_criminal_in_faith_trigger = {
					TRAIT = cannibal
					GENDER_CHARACTER = root
					FAITH = root.faith
				}
				NOT = { has_trait = cannibal }
			}
			add_trait = cannibal
		}
		10 = {
			trigger = {
				trait_is_criminal_in_faith_trigger = {
					TRAIT = deviant
					GENDER_CHARACTER = root
					FAITH = root.faith
				}
				NOT = { has_trait = deviant }
			}
			add_trait = deviant
		}
		10 = {
			trigger = {
				trait_is_criminal_in_faith_trigger = {
					TRAIT = fornicator
					GENDER_CHARACTER = root
					FAITH = root.faith
				}
				NOT = { has_trait = fornicator }
			}
			add_trait = fornicator
		}
	}
}

clear_hostile_actions_lock_flag_effect = {
	if = {
		limit = { has_character_flag = flag_hostile_actions_disabled_delay }
		remove_character_flag = flag_hostile_actions_disabled_delay
	}
}

ep3_hof_ask_for_influence_interaction_effect = {
	scope:actor = {
		if = {
			limit = {
				domicile ?= {
					has_domicile_parameter = influence_gain_from_hof_support_6
				}
			}
			change_influence = ep3_requested_faith_support_6_value
			custom_tooltip = requested_faith_support_domicile_tt
		}
		else_if = {
			limit = {
				domicile ?= {
					has_domicile_parameter = influence_gain_from_hof_support_5
				}
			}
			change_influence = ep3_requested_faith_support_5_value
			custom_tooltip = requested_faith_support_domicile_tt
		}
		else_if = {
			limit = {
				domicile ?= {
					has_domicile_parameter = influence_gain_from_hof_support_4
				}
			}
			change_influence = ep3_requested_faith_support_4_value
			custom_tooltip = requested_faith_support_domicile_tt
		}
		else_if = {
			limit = {
				domicile ?= {
					has_domicile_parameter = influence_gain_from_hof_support_3
				}
			}
			change_influence = ep3_requested_faith_support_3_value
			custom_tooltip = requested_faith_support_domicile_tt
		}
		else_if = {
			limit = {
				domicile ?= {
					has_domicile_parameter = influence_gain_from_hof_support_2
				}
			}
			change_influence = ep3_requested_faith_support_2_value
			custom_tooltip = requested_faith_support_domicile_tt
		}
		else_if = {
			limit = {
				domicile ?= {
					has_domicile_parameter = influence_gain_from_hof_support_1
				}
			}
			change_influence = ep3_requested_faith_support_1_value
			custom_tooltip = requested_faith_support_domicile_tt
		}
		else = {
			change_influence = ep3_requested_faith_support_0_value
		}
		house = {
			add_house_modifier = {
				modifier = ep3_requested_faith_support_modifier
				years = 10
			}
		}
		
		reverse_add_opinion = {
			target = scope:recipient
			modifier = requested_influence_opinion
			opinion = -30
		}
	}
	scope:actor = {
		if = {
			limit = {
				scope:hook = no
			}
			add_piety = massive_piety_loss
		}
		if = {
			limit = { always = scope:hook }
			use_hook = scope:recipient
		}
	}
}
